package com.nanhang.controller;

import com.nanhang.common.util.PageResult;
import com.nanhang.common.util.R;
import com.nanhang.entity.Order;
import com.nanhang.service.OrderService;
import com.nanhang.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService OrderService;
    @GetMapping("/list")
    public R findAll(){
        List<Order> list = OrderService.list();
        return R.ok().data("list",list);
    }
    //删除
    @DeleteMapping("/delete/{ids}")
    public R delete(@PathVariable("ids") String ids){  // 1,2,3
        String[] split = ids.split(",");
        List<String> eids = Arrays.asList(split);
        return OrderService.removeByIds(eids) ? R.ok().message("删除订单成功!") : R.error().message("删除订单失败!"+eids);
    }
    //修改
    @PutMapping("/update")
    public R update(@RequestBody Order order){
        boolean flag = OrderService.updateById(order);
        return flag ? R.ok().message("修改订单成功!") : R.error().message("修改订单失败!");
    }
    //添加
    @PostMapping("/add")
    public R add(@RequestBody Order order){
        boolean flag = OrderService.add(order);
        return flag ? R.ok().message("添加订单成功!") : R.error().message("添加订单失败!");
    }

}

